import $ from 'jQuery';
(function () {
    //let storeParams = JSON.parse(IOT.getSessionStore(URI.OPERATE.GROUPS.CREATE.PAGE));
    let $vue = new Vue({
        el: '.groups-create-hook',
        data: {
            account: {
                "ctime": "",
                "cuser": "",
                "groupCode": "",
                "groupName": "",
                "groupNote": "",
                "groupState": "",
                "proId": "",
                "userId": "",
                "utime": "",
                "uuser": ""
            }
        },
        created: function () {
            //获取所属项目下拉
            //获取维护人下拉
        },
        methods: {
            goBack: function () {
                M.Page.emitPrePage();
            }
        },
        mounted: function () {
            this.$nextTick(() => {
                $('.create-form-hook').validate({
                    debug: true,
                    rules: {
                        groupName: {
                            required: true,
                            minlength: 1,
                            maxlength: 20
                        },
                        proId: {
                            required: true,
                            minlength: 1,
                            maxlength: 20
                        },
                        userId: {
                            required: true,
                            minlength: 1,
                            maxlength: 10
                        },
                        groupNote:{
                            maxlength: 500
                        }
                    },
                    submitHandler: function (form) {
                        /*if($.trim($vue.$data.account.userName) == ""){
                            layer.alert('用户姓名不能为空');
                            return false;
                        }*/
                        IOT.showOverlay('保存中，请稍等...');
                        let params = $vue.$data.account;
                        IOT.getServerData(URI.OPERATE.GROUPS.CREATE.SAVE, params, function (ret) {
                            IOT.hideOverlay();
                            if (ret && ret.code === 200) {
                                IOT.tips('保存成功！', 'success');
                                M.Table.refresh.all();
                                M.Page.emitPrePage();
                            } else {
                                IOT.tips(ret.msg || '操作失败，请重试！', 'error', 1000, null);
                            }
                        });
                        return false;
                    }
                });
            });
        }
    });
})();